﻿// <copyright file="admin_Basic_Information.aspx.cs" company="NTalent">
// Copyright (c) 2010, NTalent, Inc. All rights reserved
// </copyright>
// <author>卢俊坤</author>
// <author>王彦博 符茂松</author>

using System;
using Net.Ntalent.Action50.Core.Controls;
using Net.Ntalent.Action50.Core.Util;
using Net.Ntalent.Action50.DataAccess;
using Net.Ntalent.Action50.Core.Service;

/// <summary>
/// 管理页面，显示某一个action的基本信息
/// </summary>
///<author>王彦博</author> 
/// <copyright>
/// Copyright (c) 2010, NTalent, Co. Ltd. All rights reserved.
/// </copyright>
/// <version>1.0.0</version>
public partial class admin_Basic_Information : PageBase
{
    /// <summary>
    /// 构造函数
    /// </summary>
    public admin_Basic_Information()
    {
        //设置权限，使未登录用户不能访问该页
        authentication = Constants.AUTHENTICATION_ADMIN;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        //如果查询字符串中没有actionId参数
        if (Helper.getQueryString(this.Context, "actionId") == string.Empty)
        {
            return;
        }

        //如果不是回发，则从数据库中提取该action的基本信息加载到页面中
        if (!IsPostBack)
        {
            T_ACTIONS action = new ReadOnlyService().RetrieveAction(Convert.ToInt64(Request.QueryString["actionId"]));
            ScroLeft.Text = action.SHORT_INTRO;
            tb_Name.Text = action.ACTION_NAME;
            tb_Member.Text = action.EFFECT_PEOPLE_COUNT.ToString();
            FCKeditor1.Value = action.TEAMS_INTRO;
        }
    }

    /// <summary>
    /// 更新action基本信息
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        try
        {
            T_ACTIONS action = new ReadOnlyService().RetrieveAction(Convert.ToInt64(Request.QueryString["actionId"]));
            action.SHORT_INTRO = HTMLFilter.Strip(ScroLeft.Text.Trim());
            action.ACTION_NAME = HTMLFilter.Strip(tb_Name.Text.Trim());
            action.TEAMS_INTRO = Helper.FiltScriptAndStyle(FCKeditor1.Value);
            action.EFFECT_PEOPLE_COUNT = Convert.ToInt64(tb_Member.Text);
            new EditService().UpdateAction(action);

            //弹出提示，更新成功
            Message.Text = "Update Action Successfully！";
            popupCmd.Text =
                "<script type='text/javascript'>$('.popup').css('display', 'block');$('#alpha').css('display', 'block');</script>";
        }
        catch
        {
            //弹出提示，更新失败
            Message.Text = "Update Action Failed！";
            popupCmd.Text =
                "<script type='text/javascript'>$('.popup').css('display', 'block');$('#alpha').css('display', 'block');</script>";
        }
    }

    /// <summary>
    /// Logout
    /// </summary>
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        AuthenticationService authenticationService = new AuthenticationService();
        authenticationService.LogOut();
        Response.Redirect(Request.UrlReferrer.ToString());
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        popupCmd.Text = string.Empty;
    }
}
